LIBCOMMON=../..
CC=gcc
CFLAGS=-Wall -g
INCLS=-I$(LIBCOMMON)/include

LIBS_ORAPROC=-L$(LIBCOMMON)/lib -lcommon -L$(ORACLE_HOME)/lib -lclntsh -lpthread -lm -lresolv

LIBS_MYSQLC=-L$(LIBCOMMON)/lib -lcommon
ifeq ($(shell if test -d /usr/local/mysql; then echo Y; else echo N; fi), Y)
    LIBS_MYSQLC+=-L/usr/local/mysql/lib
else
    LIBS_MYSQLC+=-L/usr/lib/mysql
endif
LIBS_MYSQLC+=-lmysqlclient_r -lpthread -lm -lz

LIBS_PGC=-L$(LIBCOMMON)/lib -lcommon
ifeq ($(shell if test -d /usr/local/pgsql; then echo Y; else echo N; fi), Y)
    LIBS_PGC+=-L/usr/local/pgsql/lib
else
    LIBS_PGC+=-L/usr/lib/pgsql
endif
LIBS_PGC+=-lpq -lpthread -lm -lz

OS=$(shell uname)
ifeq ($(OS), Linux)
    LIBS_ORAPROC+=-lnsl -lrt
endif
ifeq ($(OS), Darwin)
endif

all : oraproc mysqlc pgc

oraproc : my_emp.c my_emp_mt.c
	$(CC) $(CFLAGS) -D_DBC_ORACLE $(INCLS) -o my_emp_oraproc my_emp.c $(LIBS_ORAPROC)
	$(CC) $(CFLAGS) -D_DBC_ORACLE $(INCLS) -o my_emp_oraproc_mt my_emp_mt.c $(LIBS_ORAPROC)
	chmod 744 my_emp_oraproc my_emp_oraproc_mt 

mysqlc : my_emp.c my_emp_mt.c
	$(CC) $(CFLAGS) -D_DBC_MYSQL $(INCLS) -o my_emp_mysqlc my_emp.c $(LIBS_MYSQLC)
	$(CC) $(CFLAGS) -D_DBC_MYSQL $(INCLS) -o my_emp_mysqlc_mt my_emp_mt.c $(LIBS_MYSQLC)
	chmod 744 my_emp_mysqlc my_emp_mysqlc_mt 

pgc : my_emp.c my_emp_mt.c
	$(CC) $(CFLAGS) -D_DBC_PGSQL $(INCLS) -o my_emp_pgc my_emp.c $(LIBS_PGC)
	$(CC) $(CFLAGS) -D_DBC_PGSQL $(INCLS) -o my_emp_pgc_mt my_emp_mt.c $(LIBS_PGC)
	chmod 744 my_emp_pgc my_emp_pgc_mt 

clean :
	rm -f core* my_emp_oraproc my_emp_oraproc_mt my_emp_mysqlc my_emp_mysqlc_mt my_emp_pgc my_emp_pgc_mt
